<template>
<div>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/welcome' }">通用大数据框架智能计算引擎优化仿真平台</el-breadcrumb-item>
    <el-breadcrumb-item>计算任务</el-breadcrumb-item>
    <el-breadcrumb-item>优化对比</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card>
    <el-row :gutter="15">
      <el-col :span="8">
        <el-input placeholder="请输入内容" v-model="queryInfo.query" class="input-with-select" clearable @clear="getOptimizationComparisonList">
          <el-button slot="append" icon="el-icon-search" @click="getOptimizationComparisonList"></el-button>
        </el-input>


      </el-col>
      <el-col :span="4">
        <el-button type="primary"  @click="addComparsionTask">创建对比任务</el-button>
      </el-col>
    </el-row>
<!-- 表格站位-->
<tree-table :data="optimizationComparisonList" :columns="columns" :selection-type=false :expand-type=false>
  <template slot="opt" slot-scope="scope">

    <el-button type="primary" icon="el-icon-edit"  @click="showeditCateDialog(scope.row)"></el-button>
    <el-button type="danger" icon="el-icon-delete"  @click="remove(scope.row)"></el-button>
    <el-button type="primary" icon="" v-if="scope.row.comparetaskid !==undefined">优化对比</el-button>

  </template>

</tree-table>



    <el-pagination
        @size-change="SizeChange"
        @current-change="CurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10,20,30]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
    <el-dialog
        title="编辑对比任务"
        :visible.sync="editCompaDialogVisbel"
        width="30%"
    >
      <el-form :model=" editComPrams"  label-width="100px" class="demo-ruleForm">
        <el-form-item label="名称" prop="optimizeschemenamename" >
          <el-input v-model="editComPrams.comparetaskname"  ></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="editCompaDialogVisbel = false">取 消</el-button>
     <el-button type="primary" @click="editCompaDialogVisbelsubmit">确 定</el-button>
     </span>
    </el-dialog>
    <el-dialog
        title="编辑计算任务"
        :visible.sync="editDialogVisbel"
        width="30%"
    >
      <el-form :model=" editPrams"  label-width="100px" class="demo-ruleForm">
        <el-form-item label="名称" prop="optimizeschemenamename" >
          <el-input v-model="editPrams.taskname"  ></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="editDialogVisbel = false">取 消</el-button>
     <el-button type="primary" @click="editDialogVisbelsubmit">确 定</el-button>
     </span>
    </el-dialog>


    <el-dialog
        title="创建对比任务"
        :visible.sync="addComparsionVisble"
        width="20%"
    >
      <el-form :model="addComparetaskForm"  ref="addComparetaskFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="对比任务名称" prop="calculationname">
          <el-input v-model="addComparetaskForm.addComparetaskFormname"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
     <el-button @click="addComparsionVisble = false">取 消</el-button>
     <el-button type="primary" @click="addComparsionsubmit">确 定</el-button>
     </span>
    </el-dialog>
  </el-card>
</div>
</template>
<script>
export default {
  data(){
    return{
      queryInfo:{
        //查询参数
        query:'',
        pagenum:1,
        pagesize:10
      },
      editPrams:{},
      editDialogVisbel:false,
      addComparsionVisble:false,
      editComPrams:{},
    editCompaDialogVisbel:false,
      editid:'',
      total:0,
      optimizationComparisonList: [],
      optimizationComparisonListTest:[
        {
          comparetaskid:'01',
          comparetaskname:'对比任务01',

          children:[
            {
              taskid:'001',
              taskname:'计算任务01',
              taskstarttime:'2022',
              timeconsuming:'10h',
              container:'默认容器',
              optimizationscheme:'默认方案',
            },
            {
              taskid:'002',
              taskname:'计算任务02',
              taskstarttime:'2022',
              timeconsuming:'10h',
              container:'默认容器',
              optimizationscheme:'默认方案',
            },

          ]


        },
        {
          comparetaskid:'02',
          comparetaskname:'对比任务02',

          children: [
            { taskid:'003',
              taskname:'计算任务03',
              taskstarttime:'2023',
              timeconsuming:'10h',
              container:['默认容器',' 图像处理容器'],
              optimizationscheme:'默认方案',}
          ]


        },
        {
          comparetaskid:'02',
          comparetaskname:'对比任务02',

          children: [
            // { taskid:'003',
            //   taskname:'计算任务03',
            //   taskstarttime:'2023',
            //   timeconsuming:'10h',
            //   container:['默认容器',' 图像处理容器'],
            //   optimizationscheme:'默认方案',}
          ]


        }
      ],
      gettask:[],
      tasktest:[
        {
          lable:'任务01',
          value:'1'
        },
    {
      lable:'任务02',
          value:'2'
    }
      ],
      columns:[
        {
          label: '名称',
          prop:'comparetaskname'
        },
        {
          label: '计算任务名称',
          prop:'taskname'
        },
        {
          label: '开始时间',
          prop:'taskstarttime'
        },
        {
          label: '耗时',
          prop:'timeconsuming'
        },
        {
          label: '容器',
          prop:'container'
        },
        {
          label: '优化方案',
          prop:'optimizationscheme'
        },
        {
          label: '操作',
          type:'template',
          template:'opt'
        },

      ],
      addComparetaskForm:{
        addComparetaskFormname:''
      }


    }
  },
  methods:{
    SizeChange(newsize){
      this.queryInfo.pagesize = newsize
      this. getOptimizationComparisonList()
    },
    CurrentChange(newnumber){
      this.queryInfo.pagenum = newnumber
      this. getOptimizationComparisonList()
    },
    getOptimizationComparisonList(){
      this.$http.get('/',{params:this.queryInfo}).then(res=>{
            console.log(res)
            this.optimizationComparisonList = this.optimizationComparisonListTest
            // if(res.data.meta.status !== 200)
            // return this.$message.error('请求任务详情列表失败')
            // this.optimizationComparisonList = res.data.data.optimizationComparisonList
            // this.total = res.data.data.total
            this.total = 0
      })
    },


    remove(row){
      console.log(row)
    },
    showeditCateDialog(row) {
      if(row.comparetaskid !== undefined){
        this.editid = row.comparetaskid
        this.$http.get('' + this.editid)
        for (let i = 0; i < this.optimizationComparisonList.length; i++) {
          if(this.editid===this.optimizationComparisonList[i].comparetaskid){
            this.editComPrams = this.optimizationComparisonList[i]
          }

        }

        this.editCompaDialogVisbel = true
      }else {
        this.editid = row.taskid
        this.$http.get('' + this.editid)
        for (let i = 0; i < this.optimizationComparisonList.length; i++) {
          for (let j = 0; j < this.optimizationComparisonList[i].children.length; j++) {
            if (this.editid === this.optimizationComparisonList[i].children[j].taskid) {
              this.editPrams = this.optimizationComparisonList[i].children[j]
            }

          }
        }
        this.editDialogVisbel = true

      }

    },
    editCompaDialogVisbelsubmit(){
      this.$http.post('/',this.editComPrams).then(res=>{
        console.log(res)

      })
      this.editCompaDialogVisbel = false
      this.getOptimizationComparisonList()
    },
    editDialogVisbelsubmit(){
      this.$http.post('/',this.editPrams).then(res=>{
        console.log(res)

      })
      this.editDialogVisbel = false
      this.getOptimizationComparisonList()
    },
    addComparsionTask(){
    this.$http.get('/' ).then(res=>{
      console.log(res)
      this.gettask = this.tasktest
    })

      this.addComparsionVisble = true

    },
    addComparsionsubmit(){

      this.$http.post('/',this.addComparetaskForm).then(res=>{
        console.log(res)

      })
      this.addComparsionVisble = false
      this.getOptimizationComparisonList()

    }

  },
  created() {
    this.getOptimizationComparisonList()
  }
}

</script>
<style>

</style>
